﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_StdModelConfig : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "StdPhrAssocWordDict");

            migrationBuilder.RenameColumn(
                name: "ModelCodg",
                table: "MainStdModelConfig",
                newName: "ModelCode");

            migrationBuilder.AlterColumn<string>(
                name: "Wubicode",
                table: "MainDeptInfo",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.AlterColumn<string>(
                name: "Pinyincode",
                table: "MainDeptInfo",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameColumn(
                name: "ModelCode",
                table: "MainStdModelConfig",
                newName: "ModelCodg");

            migrationBuilder.AlterColumn<string>(
                name: "Wubicode",
                table: "MainDeptInfo",
                type: "text",
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Pinyincode",
                table: "MainDeptInfo",
                type: "text",
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.CreateTable(
                name: "StdPhrAssocWordDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StdModelConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdWordDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StdPhrAssocWordDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StdPhrAssocWordDict_MainStdModelConfig_StdModelConfigId",
                        column: x => x.StdModelConfigId,
                        principalTable: "MainStdModelConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_StdPhrAssocWordDict_MainStdWordDict_StdWordDictId",
                        column: x => x.StdWordDictId,
                        principalTable: "MainStdWordDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_StdPhrAssocWordDict_StdModelConfigId",
                table: "StdPhrAssocWordDict",
                column: "StdModelConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_StdPhrAssocWordDict_StdWordDictId",
                table: "StdPhrAssocWordDict",
                column: "StdWordDictId");
        }
    }
}
